
Command to add paths in matlab:

```matlab
% matlab
cd ~/storage/MyProject/fairAI/HCP_race/scripts/Unfairness_HCP_process
HCP_addpath
```

## Step 1: Split AA into 10 folds

```matlab
% matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/HCP_race';
for seed = 1:400
    HCP_split_AA_rm_hardtomatch(fullfile(proj_dir, 'scripts', 'lists', 'subjects_wIncome_948.txt'), ...
        fullfile(proj_dir, 'scripts', 'lists', 'hard_to_match_AA.txt'), 10, seed, ...
        fullfile(proj_dir, 'mat', 'split_AA_948_rm_outliers18', ['split_seed' num2str(seed) '.mat']));
end
```

## Step 2: Within each AA fold, find matched WA

```bash
# bash
ssh headnode
cd ~/storage/MyProject/fairAI/HCP_race/scripts/Unfairness_HCP_process/match_split
./HCP_match_WA_with_AAfolds.sh -max_seed 400 -outdir \
    /home/jingweil/storage/MyProject/fairAI/HCP_race/mat/split_WA_rm_AA_outliers18
```

## Step 3: Check if the difference in demographic & behavioral distributions between AA & WA were significant

```matlab
% matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/HCP_race';
HCP_AA_WA_match_diff(fullfile(proj_dir, 'mat', 'split_AA_948_rm_outliers18'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'subjects_wIncome_948.txt'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'FD_948.txt'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'FD_948.txt'), 'NONE', ...
    fullfile(proj_dir, 'scripts', 'lists', 'Cognitive_Personality_Task_Social_Emotion_58.txt'), 400, ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', 'stats_ks_tt.mat'))
```

For each behavioral measures, the first 40 random splits with matched AA & WA were selected. The selected (seed, behavior) combinations were saved as text lists by the following script:

```matlab
% matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/HCP_race';
HCP_select_matched_seeds(fullfile(proj_dir, 'mat', 'split_AA_948_rm_outliers18'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', 'stats_ks_tt.mat'), 400, ...
    fullfile(proj_dir, 'scripts', 'lists', 'Cognitive_Personality_Task_Social_Emotion_58.txt'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', 'usable_seeds'))
```

## Step 4: split the remaining subjects

```bash
# bash
ssh headnode
cd ~/storage/MyProject/fairAI/HCP_race/scripts/Unfairness_HCP_process/match_split
./HCP_split_except_selectedAAWA.sh -max_seed 400 -outdir \
    /home/jingweil/storage/MyProject/fairAI/HCP_race/mat/split_except_AA_WA_rm_AA_outliers18
```

## Step 5: combine the splits of AA, splits of matched WA, and splits of other subjects

```matlab
% matlab
for seed = 1:400
    proj_dir = '/home/jingweil/storage/MyProject/fairAI/HCP_race';
    matched_bhvr_ls = fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', ...
        'usable_seeds', ['usable_behaviors_seed' num2str(seed) '.txt']); 
    if(exist(matched_bhvr_ls, 'file')) 
        HCP_combine_AA_WA_others_folds(fullfile(proj_dir, 'mat', 'split_AA_948_rm_outliers18', ...
            ['split_seed' num2str(seed) '.mat']), fullfile(proj_dir, 'mat', ...
            'split_WA_rm_AA_outliers18', ['split_seed' num2str(seed) '.mat']), ...
            fullfile(proj_dir, 'mat', 'split_except_AA_WA_rm_AA_outliers18', ...
            ['split_seed' num2str(seed) '.mat']), fullfile(proj_dir, 'scripts', 'lists', ...
            'subjects_wIncome_948.txt'), fullfile(proj_dir, 'scripts', 'lists', ...
            'Cognitive_Personality_Task_Social_Emotion_58.txt'), matched_bhvr_ls, ...
            fullfile(proj_dir, 'mat', 'combine_AA_matchedWA_others_rm_AA_outliers18', ...
            ['split_seed' num2str(seed)]))
    end
end
```

## Step 6: compare variances of true behavioral scores between matched AA and WA (Levene's test)

```matlab
% matlab
proj_dir = '/home/jingweil/storage/MyProject/fairAI/HCP_race';
HCP_pheno_var_AAvsWA_matched(fullfile(proj_dir, 'mat', 'split_AA_948_rm_outliers18'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18'), ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', 'AAvsWA_var_Levene.mat'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'subjects_wIncome_948.txt'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'Cognitive_Personality_Task_Social_Emotion_51_matched.txt'), ...
    fullfile(proj_dir, 'scripts', 'lists', 'Cognitive_Personality_Task_Social_Emotion_58.txt'), 400, ...
    fullfile(proj_dir, 'mat', 'split_WA_rm_AA_outliers18', 'usable_seeds'))
```

